home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / src / Rkm_asm.lha / Assembly_Codes / OS_Sources / Handler / AddNH.s next >
Text File  |  1992-09-02  |  20KB  |  1,079 lines

  1.  
  2.  * Memory Buffer addresses.
  3.  *
  4.  *   0  Startup Return Message
  5.  *   4  _DOSBase
  6.  *   8  _IntuitionBase
  7.  *  12 _IconBase
  8.  *  16 Old Directory from CurrentDir()
  9.  *  20 Disk Object from GetDiskObject()
  10.  *  24 Argument addresses (30*4)
  11.  * 144 ReadArgs() return value
  12.  * 148 Input Port
  13.  * 152 Input IO
  14.  * 156 Handler's Interrupt
  15.  * 160 Game Port
  16.  * 164 Game IO
  17.  * 168 Keyboard Port
  18.  * 172 Keyboard IO
  19.  * 176 Task address
  20.  * 180 NUMERICPAD Port
  21.  * 184 Trackdisk Port
  22.  * 188 Trackdisk IO
  23.  * 192 _GfxBase
  24.  * 196 pmcommand 
  25.  * 198 pmaction
  26.  * 200 controller 
  27.  * 201 gameport
  28.  * 202 Keyboard Buffer
  29.  * 218 pmstatus
  30.  * 219 status
  31.  * 220 pmdata
  32.  * 221 Handler Priority
  33.  * 222 pmseconds
  34.  * 226 pmmicros
  35.  * 230 _InputBase
  36.  * 234 border
  37.  * 235
  38.  * 236
  39.  *
  40.  
  41.     INCDIR    WORK:Include/
  42.  
  43.     INCLUDE    work:devpac/large.gs
  44.     INCLUDE    misc/missing_keys.i
  45.  
  46. LIB_VER        EQU    39
  47. TRUE        EQU    -1
  48. FALSE        EQU    0
  49.  
  50.     lea    membuf(pc),a4
  51.  
  52.     move.b    #1,200(a4)        ; Default Controller (Mouse)
  53.     move.b    #100,221(a4)        ; Default Handler Priority
  54.  
  55.     suba.l    a1,a1
  56.     move.l    4.w,a6
  57.     jsr    _LVOFindTask(a6)
  58.     tst.l    d0
  59.     beq    exit
  60.     move.l    d0,a5
  61.     move.l    a5,176(a4)
  62.     tst.l    pr_CLI(a5)        ; Was this task started from CLI?
  63.     bne.s    _main            ; Yes.
  64.     lea    pr_MsgPort(a5),a0    ; No. From Workbench.
  65.     jsr    _LVOWaitPort(a6)
  66.     lea    pr_MsgPort(a5),a0
  67.     jsr    _LVOGetMsg(a6)
  68.     move.l    d0,(a4)            ; D0 = A WBStartup Message.
  69.  
  70. _main
  71.     moveq    #LIB_VER,d0
  72.         lea     dos_name(pc),a1
  73.     move.l    4.w,a6
  74.         jsr    _LVOOpenLibrary(a6)
  75.         move.l  d0,4(a4)
  76.         beq     quit
  77.  
  78.         moveq    #LIB_VER,d0
  79.         lea     int_name(pc),a1
  80.         jsr    _LVOOpenLibrary(a6)
  81.         move.l  d0,8(a4)
  82.         beq     cl_dos
  83.  
  84.         moveq    #LIB_VER,d0
  85.         lea     gfx_name(pc),a1
  86.         jsr    _LVOOpenLibrary(a6)
  87.         move.l  d0,192(a4)
  88.         beq     cl_int
  89.  
  90.         moveq    #LIB_VER,d0
  91.         lea     icon_name(pc),a1
  92.         jsr    _LVOOpenLibrary(a6)
  93.         move.l  d0,12(a4)
  94.         beq     cl_gfx
  95.  
  96.  * Check the ToolTypes/CLI Arguments.
  97.  
  98.         move.l    (a4),a0
  99.         tst.l   a0
  100.         beq    fromcli
  101.     move.l    sm_ArgList(a0),a5
  102.         move.l  (a5),d1
  103.     beq    zero_args
  104.     move.l    4(a4),a6
  105.     jsr    _LVOCurrentDir(a6)
  106.         move.l  d0,16(a4)
  107.         move.l    wa_Name(a5),a0
  108.     move.l    12(a4),a6
  109.     jsr    _LVOGetDiskObject(a6)
  110.         move.l  d0,20(a4)
  111.         beq     zero_args
  112.         move.l    d0,a5
  113.         move.l  do_ToolTypes(a5),a5
  114.  
  115.     move.l    a5,a0
  116.         lea    ftstg0(pc),a1
  117.         jsr    _LVOFindToolType(a6)
  118.     tst.l    d0
  119.         beq.s    tt1
  120.     move.l    d0,a3
  121.     move.l    a3,a0
  122.     lea    mtstg0(pc),a1
  123.     jsr    _LVOMatchToolValue(a6)
  124.     tst.l    d0
  125.     beq.s    tto1
  126.     clr.b    201(a4)
  127.     bra.s    tt1
  128. tto1    move.l    a3,a0
  129.     lea    mtstg1(pc),a1
  130.     jsr    _LVOMatchToolValue(a6)
  131.     tst.l    d0
  132.     beq.s    tt1
  133.     move.b    #1,201(a4)
  134. tt1    move.l    a5,a0
  135.         lea    ftstg1(pc),a1
  136.         jsr    _LVOFindToolType(a6)
  137.     tst.l    d0
  138.         beq.s    tt2
  139.     move.l    d0,a3
  140.     move.l    a3,a0
  141.     lea    mtstg2(pc),a1
  142.     jsr    _LVOMatchToolValue(a6)
  143.     tst.l    d0
  144.     beq.s    tto2
  145.     clr.b    200(a4)
  146.     bra.s    tt2
  147. tto2    move.l    a3,a0
  148.     lea    mtstg3(pc),a1
  149.     jsr    _LVOMatchToolValue(a6)
  150.     tst.l    d0
  151.     beq.s    tto3
  152.     move.b    #1,200(a4)
  153.     bra.s    tt2
  154. tto3    move.l    a3,a0
  155.     lea    mtstg4(pc),a1
  156.     jsr    _LVOMatchToolValue(a6)
  157.     tst.l    d0
  158.     beq.s    tto4
  159.     move.b    #2,200(a4)
  160.     bra.s    tt2
  161. tto4    move.l    a3,a0
  162.     lea    mtstg5(pc),a1
  163.     jsr    _LVOMatchToolValue(a6)
  164.     tst.l    d0
  165.     beq.s    tt2
  166.     move.b    #3,200(a4)
  167. tt2    move.l    a5,a0
  168.         lea    ftstg2(pc),a1
  169.         jsr    _LVOFindToolType(a6)
  170.     tst.l    d0
  171.         beq.s    tt3
  172.     move.l    d0,a3
  173.     move.l    a3,a0
  174.     lea    mtstg6(pc),a1
  175.     jsr    _LVOMatchToolValue(a6)
  176.     tst.l    d0
  177.     beq.s    tto5
  178.     clr.b    234(a4)
  179.     bra.s    tt3
  180. tto5    move.l    a3,a0
  181.     lea    mtstg7(pc),a1
  182.     jsr    _LVOMatchToolValue(a6)
  183.     tst.l    d0
  184.     beq.s    tt3
  185.     move.b    #1,234(a4)
  186. tt3    move.l    a5,a0
  187.         lea    ftstg3(pc),a1
  188.         jsr    _LVOFindToolType(a6)
  189.     tst.l    d0
  190.         beq.s    tt4
  191.     move.l    d0,a3
  192.     move.l    a3,a0
  193.     lea    mtstg8(pc),a1
  194.     jsr    _LVOMatchToolValue(a6)
  195.     tst.l    d0
  196.     beq.s    tto6
  197.     move.b    #-32,221(a4)
  198.     bra.s    tt4
  199. tto6    move.l    a3,a0
  200.     lea    mtstg9(pc),a1
  201.     jsr    _LVOMatchToolValue(a6)
  202.     tst.l    d0
  203.     beq.s    tto7
  204.     move.b    #-16,221(a4)
  205.     bra.s    tt4
  206. tto7    move.l    a3,a0
  207.     lea    mtstg10(pc),a1
  208.     jsr    _LVOMatchToolValue(a6)
  209.     tst.l    d0
  210.     beq.s    tto8
  211.     clr.b    221(a4)
  212.     bra.s    tt4
  213. tto8    move.l    a3,a0
  214.     lea    mtstg11(pc),a1
  215.     jsr    _LVOMatchToolValue(a6)
  216.     tst.l    d0
  217.     beq.s    tto9
  218.     move.b    #16,221(a4)
  219.     bra.s    tt4
  220. tto9    move.l    a3,a0
  221.     lea    mtstg12(pc),a1
  222.     jsr    _LVOMatchToolValue(a6)
  223.     tst.l    d0
  224.     beq.s    tt4
  225.     move.b    #32,221(a4)
  226. tt4
  227.     nop
  228.  
  229.  
  230. free_diskobj
  231.         move.l    20(a4),a0
  232.         jsr    _LVOFreeDiskObject(a6)
  233.     bra    zero_args
  234.  
  235. fromcli    lea    template(pc),a0
  236.     move.l  a0,d1
  237.         lea    24(a4),a5
  238.         move.l  a5,d2
  239.         moveq    #0,d3
  240.     move.l    4(a4),a6
  241.         jsr    _LVOReadArgs(a6)
  242.         move.l  d0,144(a4)
  243.         beq    zero_args
  244.  
  245.     move.l    (a5),a0
  246.     lea    mtstg0(pc),a1
  247.     bsr    cmpbyte
  248.     tst.l    d0
  249.     bne.s    cao1
  250.     clr.b    201(a4)
  251.     bra.s    ca1
  252. cao1    move.l    (a5),a0
  253.     lea    mtstg1(pc),a1
  254.     bsr    cmpbyte
  255.     tst.l    d0
  256.     bne.s    ca1
  257.     move.b    #1,201(a4)
  258. ca1    move.l    4(a5),a0
  259.     lea    mtstg2(pc),a1
  260.     bsr    cmpbyte
  261.     tst.l    d0
  262.     bne.s    cao2
  263.     clr.b    200(a4)
  264.     bra.s    ca2
  265. cao2    move.l    4(a5),a0
  266.     lea    mtstg3(pc),a1
  267.     bsr    cmpbyte
  268.     tst.l    d0
  269.     bne.s    cao3
  270.     move.b    #1,200(a4)
  271.     bra.s    ca2
  272. cao3    move.l    4(a5),a0
  273.     lea    mtstg4(pc),a1
  274.     bsr    cmpbyte
  275.     tst.l    d0
  276.     bne.s    cao4
  277.     move.b    #2,200(a4)
  278.     bra.s    ca2
  279. cao4    move.l    4(a5),a0
  280.     lea    mtstg5(pc),a1
  281.     bsr    cmpbyte
  282.     tst.l    d0
  283.     bne.s    ca2
  284.     move.b    #3,200(a4)
  285. ca2    move.l    8(a5),a0
  286.     lea    mtstg6(pc),a1
  287.     bsr    cmpbyte
  288.     tst.l    d0
  289.     bne.s    cao5
  290.     clr.b    234(a4)
  291.     bra.s    ca3
  292. cao5    move.l    8(a5),a0
  293.     lea    mtstg7(pc),a1
  294.     bsr    cmpbyte
  295.     tst.l    d0
  296.     bne.s    ca3
  297.     move.b    #1,234(a4)
  298. ca3    move.l    12(a5),a0
  299.     lea    mtstg8(pc),a1
  300.     bsr    cmpbyte
  301.     tst.l    d0
  302.     bne.s    cao6
  303.     move.b    #-32,221(a4)
  304.     bra.s    ca4
  305. cao6    move.l    12(a5),a0
  306.     lea    mtstg9(pc),a1
  307.     bsr    cmpbyte
  308.     tst.l    d0
  309.     bne.s    cao7
  310.     move.b    #-16,221(a4)
  311.     bra.s    ca4
  312. cao7    move.l    12(a5),a0
  313.     lea    mtstg10(pc),a1
  314.     bsr    cmpbyte
  315.     tst.l    d0
  316.     bne.s    cao8
  317.     clr.b    221(a4)
  318.     bra.s    ca4
  319. cao8    move.l    12(a5),a0
  320.     lea    mtstg11(pc),a1
  321.     bsr    cmpbyte
  322.     tst.l    d0
  323.     bne.s    cao9
  324.     move.b    #16,221(a4)
  325.     bra.s    ca4
  326. cao9    move.l    12(a5),a0
  327.     lea    mtstg12(pc),a1
  328.     bsr    cmpbyte
  329.     tst.l    d0
  330.     bne.s    ca4
  331.     move.b    #32,221(a4)
  332. ca4
  333.     nop
  334.  
  335.  
  336. free_cliargs
  337.         move.l    144(a4),d1
  338.         jsr    _LVOFreeArgs(a6)
  339.  
  340. zero_args
  341.  
  342.     move.l    4.w,a6
  343.     jsr    _LVOCreateMsgPort(a6)
  344.     move.l    d0,148(a4)
  345.     beq    cl_icon
  346.     move.l    d0,a0
  347.     moveq    #IOSTD_SIZE,d0
  348.     jsr    _LVOCreateIORequest(a6)
  349.     move.l    d0,152(a4)
  350.     beq    cl_ip
  351.     move.l    d0,a1
  352.     lea    ip_name(pc),a0
  353.     moveq    #0,d0
  354.     moveq    #0,d1
  355.     jsr    _LVOOpenDevice(a6)
  356.     tst.l    d0
  357.     bne    cl_iio
  358.     move.l    152(a4),a1
  359.     move.l    IO_DEVICE(a1),a0
  360.     move.l    a0,230(a4)
  361.  
  362.     jsr    _LVOCreateMsgPort(a6)
  363.     move.l    d0,168(a4)
  364.     beq    cl_id
  365.     move.l    d0,a0
  366.     moveq    #IOSTD_SIZE,d0
  367.     jsr    _LVOCreateIORequest(a6)
  368.     move.l    d0,172(a4)
  369.     beq    cl_kp
  370.     move.l    d0,a1
  371.     lea    kp_name(pc),a0
  372.     moveq    #0,d0
  373.     moveq    #0,d1
  374.     jsr    _LVOOpenDevice(a6)
  375.     tst.l    d0
  376.     bne    cl_kio
  377.  
  378.     jsr    _LVOCreateMsgPort(a6)
  379.     move.l    d0,160(a4)
  380.     beq    cl_kd
  381.     move.l    d0,a0
  382.     moveq    #IOSTD_SIZE,d0
  383.     jsr    _LVOCreateIORequest(a6)
  384.     move.l    d0,164(a4)
  385.     beq    cl_gp
  386.     move.l    d0,a1
  387.     lea    gp_name(pc),a0
  388.     moveq    #0,d0
  389.     moveq    #0,d1
  390.     jsr    _LVOOpenDevice(a6)
  391.     tst.l    d0
  392.     bne    cl_gio
  393.  
  394.  * Set-Up a Message Port.
  395.  
  396.         jsr    _LVOForbid(a6)
  397.         lea     portname(pc),a1
  398.         jsr    _LVOFindPort(a6)
  399.         tst.l   d0
  400.         bne.s    exists
  401.         moveq   #MP_SIZE,d0
  402.         move.l  #MEMF_PUBLIC!MEMF_CLEAR,d1
  403.         jsr    _LVOAllocMem(a6)
  404.         move.l  d0,180(a4)
  405.         beq.s    no_pmem
  406.         move.l  d0,a0
  407.         clr.l    (a0)                ; LN_SUCC(a0)
  408.         clr.l    LN_PRED(a0)
  409.         move.b  #NT_MSGPORT,LN_TYPE(a0)
  410.         clr.b    LN_PRI(a0)
  411.         lea     portname(pc),a1
  412.         move.l  a1,LN_NAME(a0)
  413.         move.b  #PA_SIGNAL,MP_FLAGS(a0)
  414.         move.l  176(a4),MP_SIGTASK(a0)
  415.         moveq    #-1,d0
  416.         jsr    _LVOAllocSignal(a6)
  417.         move.b  d0,d5
  418.         cmp.l    #-1,d0
  419.         bne.s    ad_port
  420.         jsr    _LVOPermit(a6)
  421.     bra    frmport
  422. ad_port    move.l    180(a4),a1
  423.         move.b  d5,MP_SIGBIT(a1)
  424.         jsr    _LVOAddPort(a6)
  425.         jsr    _LVOPermit(a6)
  426.     bra.s    do_hand
  427.  
  428. exists    jsr    _LVOPermit(a6)
  429.         bra     cl_gd
  430.  
  431. no_pmem    jsr    _LVOPermit(a6)
  432.         bra    cl_gd
  433.  
  434. do_hand    bsr    set_gp
  435.     bsr    set_ct
  436.     bsr    blank
  437.     bsr    ad_hand
  438.     tst.b    d2
  439.     beq    hand_err
  440.  
  441. msg_l    move.l    180(a4),a0
  442.     move.l    4.w,a6
  443.     jsr    _LVOWaitPort(a6)
  444.     move.l    180(a4),a0
  445.     jsr    _LVOGetMsg(a6)
  446.     move.l    d0,a1
  447.     move.w    pm_Command(a1),196(a4)
  448.     move.w    pm_Action(a1),198(a4)
  449.     move.l    pm_Seconds(a1),222(a4)
  450.     move.l    pm_Micros(a1),226(a4)
  451.     move.b    pm_Data(a1),220(a4)
  452.     move.b    pm_Status(a1),218(a4)
  453.  
  454.  * You can reply to a Message.
  455.  
  456.     cmp.w    #PMCOMMAND_GETSTATUS,196(a4)
  457.     bne.s    reply
  458.     move.b    219(a4),pm_Status(a1)
  459.  
  460. reply    jsr    _LVOReplyMsg(a6)
  461.  
  462.  * Check the appropriate message field/s sent to us.
  463.  
  464.     cmp.w    #PMCOMMAND_SETGAMEPORT,196(a4)
  465.     beq.s    do_gp
  466.  
  467.     cmp.w    #PMCOMMAND_SETCONTROLLER,196(a4)
  468.     beq    do_ct
  469.  
  470.     cmp.w    #PMCOMMAND_SETKEYREPEATTIME,196(a4)
  471.     beq    do_kr
  472.  
  473.     cmp.w    #PMCOMMAND_SETKEYPRESSTIME,196(a4)
  474.     beq    do_kp
  475.  
  476.     cmp.w    #PMCOMMAND_USENUMERICPAD,196(a4)
  477.     beq    do_keyb
  478.  
  479.     cmp.w    #PMCOMMAND_SETBORDER,196(a4)
  480.     beq.s    do_bb
  481.  
  482.     cmp.w    #PMCOMMAND_DISKDRIVECLICK,196(a4)
  483.     beq    do_td
  484.  
  485.  
  486.     cmp.w    #PMCOMMAND_QUIT,196(a4)
  487.     beq    exit_message
  488.  
  489.     bra    msg_l
  490.  
  491. do_gp    clr.b    201(a4)
  492.     cmp.w    #PMGAMEPORT_MOUSEINJPORT,198(a4)
  493.     beq.s    gp1
  494.     bra.s    gp_c0
  495. gp1    move.b    #1,201(a4)
  496. gp_c0    bsr.s    set_gp
  497.     bra    msg_l
  498.  
  499. set_gp    move.l    152(a4),a1
  500.     move.w    #IND_SETMPORT,IO_COMMAND(a1)
  501.     lea    201(a4),a0
  502.     move.l    a0,IO_DATA(a1)
  503.     move.l    #1,IO_LENGTH(a1)
  504.     move.l    4.w,a6
  505.     jsr    _LVODoIO(a6)
  506.     rts
  507.  
  508. do_bb    clr.b    234(a4)
  509.     cmp.w    #PMBORDER_ON,198(a4)
  510.     beq.s    bb1
  511.     bra.s    bb_c0
  512. bb1    move.b    #1,234(a4)
  513. bb_c0    bsr.s    blank
  514.     bra    msg_l
  515.  
  516. blank    move.l    192(a4),a0
  517.     lea    gb_BP3Bits(a0),a0
  518.     tst.b    234(a4)
  519.     beq.s    bb0
  520.     bset    #5,(a0)
  521.     bra.s    bb_end
  522. bb0    bclr    #5,(a0)
  523. bb_end    move.l    8(a4),a6
  524.     jsr    _LVORemakeDisplay(a6)
  525.     rts
  526.  
  527. do_ct    cmp.w    #PMCONTROLLER_NOCONTROLLER,198(a4)
  528.     beq.s    ct0
  529.     cmp.w    #PMCONTROLLER_MOUSE,198(a4)
  530.     beq.s    ct1
  531.     cmp.w    #PMCONTROLLER_RELATIVEJOYSTICK,198(a4)
  532.     beq.s    ct2
  533.     cmp.w    #PMCONTROLLER_ABSOLUTEJOYSTICK,198(a4)
  534.     beq.s    ct3
  535.     bra    msg_l
  536. ct0    clr.b    200(a4)
  537.     bra.s    sct_c0
  538. ct1    move.b    #1,200(a4)
  539.     bra.s    sct_c0
  540. ct2    move.b    #2,200(a4)
  541.     bra.s    sct_c0
  542. ct3    move.b    #3,200(a4)
  543. sct_c0    bsr.s    set_ct
  544.     bra    msg_l
  545.  
  546. set_ct    move.l    164(a4),a1
  547.     move.w    #GPD_SETCTYPE,IO_COMMAND(a1)
  548.     lea    200(a4),a0
  549.     move.l    a0,IO_DATA(a1)
  550.     move.l    #1,IO_LENGTH(a1)
  551.     move.l    4.w,a6
  552.     jsr    _LVODoIO(a6)
  553.     move.l    164(a4),a1
  554.     cmp.b    #GPDERR_SETCTYPE,IO_ERROR(a1)
  555.     beq.s    sct_end
  556.     nop
  557. sct_end    rts
  558.  
  559. do_td    cmp.w    #PMDF0CLICK_OFF,198(a4)
  560.     beq.s    td0
  561.     cmp.w    #PMDF1CLICK_OFF,198(a4)
  562.     beq.s    td1
  563.     cmp.w    #PMDF2CLICK_OFF,198(a4)
  564.     beq.s    td2
  565.     cmp.w    #PMDF3CLICK_OFF,198(a4)
  566.     beq.s    td3
  567.     cmp.w    #PMDF0CLICK_ON,198(a4)
  568.     beq.s    td4
  569.     cmp.w    #PMDF1CLICK_ON,198(a4)
  570.     beq.s    td5
  571.     cmp.w    #PMDF2CLICK_ON,198(a4)
  572.     beq.s    td6
  573.     cmp.w    #PMDF3CLICK_ON,198(a4)
  574.     beq.s    td7
  575.     bra    msg_l
  576. td0    moveq    #0,d2
  577.     bra.s    td_c3
  578. td1    moveq    #1,d2
  579.     bra.s    td_c3
  580. td2    moveq    #2,d2
  581.     bra.s    td_c3
  582. td3    moveq    #3,d2
  583. td_c3    clr.b    d3
  584.     bra.s    td_c5
  585. td4    moveq    #0,d2
  586.     bra.s    td_c4
  587. td5    moveq    #1,d2
  588.     bra.s    td_c4
  589. td6    moveq    #2,d2
  590.     bra.s    td_c4
  591. td7    moveq    #3,d2
  592. td_c4    move.b    #1,d3
  593. td_c5    bsr.s    set_td
  594.     bra    msg_l
  595.  
  596. set_td    move.l    4.w,a6
  597.     jsr    _LVOCreateMsgPort(a6)
  598.     move.l    d0,184(a4)
  599.     beq.s    scr_end
  600.     move.l    d0,a0
  601.     moveq    #IOSTD_SIZE,d0
  602.     jsr    _LVOCreateIORequest(a6)
  603.     move.l    d0,188(a4)
  604.     beq.s    cl_tdp
  605.     move.l    d0,a1
  606.     lea    td_name(pc),a0
  607.     move.l    d2,d0
  608.     moveq    #0,d1
  609.     jsr    _LVOOpenDevice(a6)
  610.     tst.l    d0
  611.     bne.s    cl_tdio
  612.     move.l    188(a4),a0
  613.     move.l    IO_UNIT(a0),a0
  614.     lea    TDU_PUBFLAGS(a0),a0
  615.     tst.b    d3
  616.     beq.s    clr_td
  617.     bset    #TDPB_NOCLICK,(a0)
  618.     bra.s    cl_td
  619. clr_td    bclr    #TDPB_NOCLICK,(a0)
  620. cl_td    move.l    188(a4),a1
  621.     jsr    _LVOCloseDevice(a6)
  622. cl_tdio    move.l    188(a4),a0
  623.     jsr    _LVODeleteIORequest(a6)
  624. cl_tdp    move.l    184(a4),a0
  625.     jsr    _LVODeleteMsgPort(a6)
  626. scr_end    rts
  627.  
  628. do_kr    move.l    152(a4),a1
  629.     move.w    #IND_SETTHRESH,IO_COMMAND(a1)
  630.     bra.s    set_krp
  631. do_kp    move.l    152(a4),a1
  632.     move.w    #IND_SETPERIOD,IO_COMMAND(a1)
  633. set_krp    lea    IOTV_TIME(a1),a0
  634.     move.l    222(a4),(a0)                ; TV_SECS(a0)
  635.     move.l    226(a4),TV_MICRO(a0)
  636.     move.l    4.w,a6
  637.     jsr    _LVODoIO(a6)
  638.     bra    msg_l
  639.  
  640. do_keyb    move.l    172(a4),a1
  641.     move.w    #KBD_READMATRIX,IO_COMMAND(a1)
  642.     lea    202(a4),a0
  643.     move.l    a0,IO_DATA(a1)
  644.     move.l    #16,IO_LENGTH(a1)
  645.     move.l    4.w,a6
  646.     jsr    _LVODoIO(a6)
  647.     move.l    172(a4),a1
  648.     move.l    IO_DATA(a1),a0        ; address of your `matrix' buffer
  649.     move.l    IO_ACTUAL(a1),d0    ; #bytes put into `matrix' buffer
  650.  
  651.     moveq    #0,d0
  652.     moveq    #0,d1
  653.     moveq    #0,d2
  654.     moveq    #0,d3
  655.     moveq    #0,d4
  656.     moveq    #0,d5
  657.     moveq    #0,d6
  658.     moveq    #0,d7
  659.     move.b    11(a0),d0
  660.     move.b    9(a0),d1
  661.     move.b    7(a0),d2
  662.     move.b    5(a0),d3
  663.     move.b    3(a0),d4
  664.     move.b    8(a0),d5
  665.     move.b    1(a0),d6
  666.     move.b    12(a0),d7
  667.     btst    #3,d7            ; see if CTRL was pressed
  668.     beq.s    ramiga
  669.     btst    #2,d0            ; see if ( was pressed
  670.     bne    do_num0
  671.     btst    #3,d0            ; see if ) was pressed
  672.     bne    do_scr0
  673.     btst    #4,d0            ; see if / was pressed
  674.     bne    do_syr0
  675.     btst    #5,d0            ; see if * was pressed
  676.     bne    do_prs0
  677.     btst    #6,d0            ; see if + was pressed
  678.     bne    do_add0
  679.     btst    #2,d1            ; see if - was pressed
  680.     bne    do_sub0
  681.     btst    #5,d2            ; see if Home was pressed
  682.     bne    do_hme0
  683.     btst    #7,d2            ; see if PgUp was pressed
  684.     bne    do_pup0
  685.     btst    #5,d4            ; see if End was pressed
  686.     bne    do_end0
  687.     btst    #7,d4            ; see if PgDn was pressed
  688.     bne    do_pdn0
  689.     btst    #7,d6            ; see if Ins was pressed
  690.     bne.s    keyb_e
  691.     bra    do_keyb
  692. ramiga    move.b    12(a0),d7
  693.     btst    #7,d7            ; see if RIGHT AMIGA was pressed
  694.     beq.s    ralt
  695.     btst    #2,d0            ; see if ( was pressed
  696.     bne.s    do_num1
  697.     btst    #3,d0            ; see if ) was pressed
  698.     bne.s    do_scr1
  699.     btst    #4,d0            ; see if / was pressed
  700.     bne.s    do_syr1
  701.     btst    #5,d0            ; see if * was pressed
  702.     bne.s    do_prs1
  703.     btst    #6,d0            ; see if + was pressed
  704.     bne.s    do_add1
  705.     btst    #2,d1            ; see if - was pressed
  706.     bne    do_sub1
  707.     btst    #5,d2            ; see if Home was pressed
  708.     bne    do_hme1
  709.     btst    #7,d2            ; see if PgUp was pressed
  710.     bne    do_pup1
  711.     btst    #5,d4            ; see if End was pressed
  712.     bne    do_end1
  713.     btst    #7,d4            ; see if PgDn was pressed
  714.     bne    do_pdn1
  715.     btst    #7,d6            ; see if Ins was pressed
  716.     bne    reset
  717.     bra    do_keyb
  718. ralt    nop
  719.     bra    do_keyb
  720.  
  721. keyb_e    move.b    #255,219(a4)    
  722.     bra    msg_l
  723.  
  724. do_num0    moveq    #0,d2
  725.     bra.s    td_c0
  726. do_scr0    moveq    #1,d2
  727.     bra.s    td_c0
  728. do_syr0    moveq    #2,d2
  729.     bra.s    td_c0
  730. do_prs0    moveq    #3,d2
  731. td_c0    clr.b    d3
  732.     bra.s    td_c2
  733. do_num1    moveq    #0,d2
  734.     bra.s    td_c1
  735. do_scr1    moveq    #1,d2
  736.     bra.s    td_c1
  737. do_syr1    moveq    #2,d2
  738.     bra.s    td_c1
  739. do_prs1    moveq    #3,d2
  740. td_c1    move.b    #1,d3
  741. td_c2    bsr    set_td
  742.     bra    do_keyb
  743.  
  744. do_add0    clr.b    201(a4)
  745.     bra.s    gp_c1
  746. do_add1    move.b    #1,201(a4)
  747. gp_c1    bsr    set_gp
  748.     bra    do_keyb
  749.  
  750. do_sub0    clr.b    234(a4)
  751.     bra.s    sub_c0
  752. do_sub1    move.b    #1,234(a4)
  753. sub_c0    bsr    blank
  754.     bra    do_keyb
  755.  
  756. do_hme0    clr.b    200(a4)
  757.     bra.s    do_sct
  758. do_pup0    move.b    #1,200(a4)
  759.     bra.s    do_sct
  760. do_pdn0    move.b    #2,200(a4)
  761.     bra.s    do_sct
  762. do_end0    move.b    #3,200(a4)
  763. do_sct    bsr    set_ct
  764.     bra    do_keyb
  765.  
  766. do_hme1
  767.  
  768.     bra    do_keyb
  769.  
  770. do_pup1
  771.  
  772.     bra    do_keyb
  773.  
  774. do_pdn1
  775.  
  776.     bra    do_keyb
  777.  
  778. do_end1
  779.  
  780.     bra    do_keyb
  781.  
  782. reset    move.l    4.w,a6
  783.     jsr    _LVOColdReboot(a6)
  784.     bra    msg_l
  785.  
  786.  
  787. exit_message
  788.     moveq    #100,d1
  789.     move.l    4(a4),a6
  790.     jsr    _LVODelay(a6)
  791.  
  792.     suba.l    a0,a0
  793.     move.l    8(a4),a6
  794.     jsr    _LVODisplayBeep(a6)
  795.  
  796.     moveq    #100,d1
  797.     move.l    4(a4),a6
  798.     jsr    _LVODelay(a6)
  799.  
  800.     suba.l    a0,a0
  801.     move.l    8(a4),a6
  802.     jsr    _LVODisplayBeep(a6)
  803.  
  804.     bsr    fr_hand
  805.     bra.s    fr_port
  806.  
  807. hand_err
  808.     nop
  809.  
  810. fr_port    move.l    180(a4),a0
  811.     tst.l    a0
  812.         beq.s    cl_gd
  813.     move.l    4.w,a6
  814.         tst.b    MP_SIGBIT(a0)
  815.         beq.s    no_sig
  816.         jsr    _LVOFreeSignal(a6)
  817. no_sig    move.l    180(a4),a1
  818.         jsr    _LVORemPort(a6)
  819. frmport    move.l    180(a4),a1
  820.         moveq   #MP_SIZE,d0
  821.     move.l    4.w,a6
  822.         jsr    _LVOFreeMem(a6)
  823.  
  824. cl_gd    move.l    164(a4),a1
  825.     move.l    4.w,a6
  826.     jsr    _LVOCloseDevice(a6)
  827.  
  828. cl_gio    move.l    164(a4),a0
  829.     move.l    4.w,a6
  830.     jsr    _LVODeleteIORequest(a6)
  831.  
  832. cl_gp    move.l    160(a4),a0
  833.     move.l    4.w,a6
  834.     jsr    _LVODeleteMsgPort(a6)
  835.  
  836. cl_kd    move.l    172(a4),a1
  837.     move.l    4.w,a6
  838.     jsr    _LVOCloseDevice(a6)
  839.  
  840. cl_kio    move.l    172(a4),a0
  841.     move.l    4.w,a6
  842.     jsr    _LVODeleteIORequest(a6)
  843.  
  844. cl_kp    move.l    168(a4),a0
  845.     move.l    4.w,a6
  846.     jsr    _LVODeleteMsgPort(a6)
  847.  
  848. cl_id    move.l    152(a4),a1
  849.     move.l    4.w,a6
  850.     jsr    _LVOCloseDevice(a6)
  851.  
  852. cl_iio    move.l    152(a4),a0
  853.     move.l    4.w,a6
  854.     jsr    _LVODeleteIORequest(a6)
  855.  
  856. cl_ip    move.l    148(a4),a0
  857.     move.l    4.w,a6
  858.     jsr    _LVODeleteMsgPort(a6)
  859.  
  860. cl_icon    move.l  12(a4),a1
  861.     move.l    4.w,a6
  862.         jsr    _LVOCloseLibrary(a6)
  863.  
  864. cl_gfx    move.l  192(a4),a1
  865.     move.l    4.w,a6
  866.         jsr    _LVOCloseLibrary(a6)
  867.  
  868. cl_int    move.l  8(a4),a1
  869.     move.l    4.w,a6
  870.         jsr    _LVOCloseLibrary(a6)
  871.  
  872. cl_dos    move.l  4(a4),a1
  873.     move.l    4.w,a6
  874.         jsr    _LVOCloseLibrary(a6)
  875.  
  876. quit    move.l  #8000000,d0
  877.         moveq    #MEMF_CHIP,d1
  878.     move.l    4.w,a6
  879.     jsr    _LVOAllocMem(a6)
  880.     tst.l    d0
  881.     beq.s    cleanup
  882.     move.l    d0,a1
  883.     move.l    #8000000,d0
  884.     jsr    _LVOFreeMem(a6)
  885. cleanup    tst.l    (a4)
  886.     beq.s    exit            ; Exit - Task was started from CLI.
  887.     move.l    4.w,a6
  888.     jsr    _LVOForbid(a6)
  889.     move.l    (a4),a1            ; Reply to the WB Startup Message and
  890.     jsr    _LVOReplyMsg(a6)    ; Exit - Task was started from WB.
  891. exit    moveq    #0,d0
  892.     rts
  893.  
  894.  
  895.  * Sub-Routines.
  896.  
  897. ad_hand    clr.b    d2
  898.     moveq    #IS_SIZE,d0
  899.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  900.     move.l    4.w,a6
  901.     jsr    _LVOAllocMem(a6)
  902.     move.l    d0,156(a4)
  903.     beq.s    ah_end
  904.     move.l    d0,a0
  905.     clr.l    (a0)
  906.     clr.l    LN_PRED(a0)
  907.     move.b    #NT_INTERRUPT,LN_TYPE(a0)
  908.     move.b    221(a4),LN_PRI(a0)
  909.     lea    is_name(pc),a1
  910.     move.l    a1,LN_NAME(a0)
  911.     clr.l    IS_DATA(a0)
  912.     lea    is_code,a1
  913.     move.l    a1,IS_CODE(a0)
  914.     move.l    152(a4),a1
  915.     move.w    #IND_ADDHANDLER,IO_COMMAND(a1)
  916.     move.l    a0,IO_DATA(a1)
  917.     move.l    #IS_SIZE,IO_LENGTH(a1)
  918.     jsr    _LVODoIO(a6)
  919.     move.b    #1,d2
  920. ah_end    rts
  921.  
  922. fr_hand    move.l    156(a4),a0
  923.     move.l    152(a4),a1
  924.     move.w    #IND_REMHANDLER,IO_COMMAND(a1)
  925.     move.l    a0,IO_DATA(a1)
  926.     move.l    #IS_SIZE,IO_LENGTH(a1)
  927.     move.l    4.w,a6
  928.     jsr    _LVODoIO(a6)
  929.     move.l    156(a4),a1
  930.     moveq    #IS_SIZE,d0
  931.     jsr    _LVOFreeMem(a6)
  932.     rts
  933.  
  934. is_code    move.l    a0,-(a7)        ; Save `event list' pointer.
  935. ic_loop    moveq    #0,d0
  936.     cmp.b    #IECLASS_RAWKEY,ie_Class(a0)
  937.     bne    next_event
  938.     move.w    ie_Qualifier(a0),d0
  939.     and.w    #IEQUALIFIER_NUMERICPAD,d0
  940.     beq.s    check_1
  941.     move.w    ie_Qualifier(a0),d0
  942.     and.w    #IEQUALIFIER_RSHIFT,d0
  943.     beq.s    check_1
  944.     move.w    ie_Code(a0),d0
  945.     and.w    #IECODE_UP_PREFIX,d0
  946.     bne    next_event
  947.     move.w    ie_Code(a0),d0
  948.     cmp.b    #$2F,d0
  949.     bne.s    sftleft
  950.         move.w  #$4E,ie_Code(a0)
  951.     bra.s    do_shft
  952. sftleft    cmp.b    #$2D,d0
  953.     bne.s    sftup
  954.         move.w  #$4F,ie_Code(a0)
  955.     bra.s    do_shft
  956. sftup    cmp.b    #$3E,d0
  957.     bne.s    sftdown
  958.         move.w  #$4C,ie_Code(a0)
  959.     bra.s    do_shft
  960. sftdown    cmp.b    #$1E,d0
  961.     bne    next_event
  962.         move.w  #$4D,ie_Code(a0)
  963. do_shft    move.b    #IECLASS_RAWKEY,ie_Class(a0)
  964.         move.w  #IEQUALIFIER_REPEAT!IEQUALIFIER_RSHIFT,ie_Qualifier(a0)
  965.     bra    next_event
  966. check_1    move.w    ie_Qualifier(a0),d0
  967.     and.w    #IEQUALIFIER_NUMERICPAD,d0
  968.     beq    check_2
  969.     move.w    ie_Code(a0),d0
  970.     and.w    #IECODE_UP_PREFIX,d0
  971.     bne    next_event
  972.     move.w    ie_Code(a0),d0
  973.     cmp.b    #$2F,d0
  974.     bne.s    numleft
  975.         move.w  #$4E,ie_Code(a0)
  976.     bra.s    do_num
  977. numleft    cmp.b    #$2D,d0
  978.     bne.s    num_up
  979.         move.w  #$4F,ie_Code(a0)
  980.     bra.s    do_num
  981. num_up    cmp.b    #$3E,d0
  982.     bne.s    numdown
  983.         move.w  #$4C,ie_Code(a0)
  984.     bra.s    do_num
  985. numdown    cmp.b    #$1E,d0
  986.     bne.s    num_del
  987.         move.w  #$4D,ie_Code(a0)
  988.     bra.s    do_num
  989. num_del    cmp.b    #$3C,d0
  990.     bne.s    num_ent
  991.         move.w  #$46,ie_Code(a0)
  992.     bra.s    do_num
  993. num_ent    cmp.b    #$43,d0
  994.     bne.s    numhome
  995.         move.w  #$44,ie_Code(a0)
  996.     bra.s    next_event
  997. numhome    cmp.b    #$3D,d0
  998.     bne.s    num_end
  999.         move.w  #$5F,ie_Code(a0)
  1000.     bra.s    do_num
  1001. num_end    cmp.b    #$1D,d0
  1002.     bne.s    num_5
  1003.         move.w  #$45,ie_Code(a0)
  1004.     bra.s    do_num
  1005. num_5    cmp.b    #$2E,d0
  1006.     bne.s    next_event
  1007.         move.w  #$40,ie_Code(a0)
  1008. do_num    move.b    #IECLASS_RAWKEY,ie_Class(a0)
  1009.         move.w  #IEQUALIFIER_REPEAT,ie_Qualifier(a0)
  1010.     bra.s    next_event
  1011. check_2    nop
  1012.  
  1013. next_event
  1014.     move.l    (a0),d0        ; get the next (ie.NextEvevnt) event.
  1015.     move.l    d0,a0
  1016.     bne    ic_loop        ; repeat until all events have been
  1017.                 ; read/altered.
  1018.  
  1019. ic_end    move.l    (a7)+,d0    ; return `event list' pointer.
  1020.     rts
  1021.  
  1022. cmpbyte    move.b  (a0)+,d0
  1023.         move.b  (a1)+,d1
  1024.         tst.b   d0
  1025.         beq.s   byte0
  1026.         cmp.b   d1,d0
  1027.         beq.s   cmpbyte
  1028. byte0    sub.b   d1,d0
  1029.         ext.w   d0
  1030.         ext.l   d0
  1031.         rts
  1032.  
  1033.  
  1034.  * String Variables.
  1035.  
  1036. int_name    dc.b    'intuition.library',0
  1037. dos_name    dc.b    'dos.library',0
  1038. icon_name       dc.b    'icon.library',0,0
  1039. gfx_name    dc.b    'graphics.library',0
  1040. ip_name        dc.b    'input.device',0,0
  1041. gp_name        dc.b    'gameport.device',0
  1042. kp_name        dc.b    'keyboard.device',0
  1043. td_name        dc.b    'trackdisk.device',0,0
  1044. is_name        dc.b    'NUMERICPAD Handler',0,0
  1045. portname        dc.b    'NUMERICPAD Port',0
  1046.  
  1047. mtstg0        dc.b    'MOUSEINMPORT',0,0
  1048. mtstg1        dc.b    'MOUSEINJPORT',0,0
  1049. mtstg2        dc.b    'NOCONTROLLER',0,0
  1050. mtstg3        dc.b    'MOUSE',0
  1051. mtstg4        dc.b    'RELATIVEJOYSTICK',0,0
  1052. mtstg5        dc.b    'ABSOLUTEJOYSTICK',0,0
  1053. mtstg6        dc.b    'BORDEROFF',0
  1054. mtstg7        dc.b    'BORDERON',0,0
  1055. mtstg8        dc.b    '-32',0
  1056. mtstg9        dc.b    '-16',0
  1057. mtstg10        dc.b    '0',0
  1058. mtstg11        dc.b    '16',0,0
  1059. mtstg12        dc.b    '32',0,0
  1060.  
  1061. ftstg0          dc.b    'SETGAMEPORT',0
  1062. ftstg1          dc.b    'SETCONTROLLER',0
  1063. ftstg2          dc.b    'SETBORDER',0
  1064. ftstg3        dc.b    'HANDLERPRIORITY',0
  1065.  
  1066. template    dc.b    'SETGAMEPORT/K,SETCONTROLLER/K,SETBORDER,HANDLERPRIORITY/K',0
  1067.  
  1068.  
  1069.  * Buffer Variables.
  1070.  
  1071. membuf        dcb.b    260,0
  1072.  
  1073.  
  1074.     SECTION    VERSION,DATA
  1075.  
  1076.     dc.b    '$VER: NUMERICPAD Handler V1.00 (17.4.2001)',0
  1077.  
  1078.  
  1079.     END